#include<cstdlib>
#include "swf.h"
#include "SWFHeader.h"
#include <iostream>

using namespace std;
using namespace swfstream;

SWFHeader* SWFHeader::from_file(FILE*f) {
	//puts("reading swf_header");
	SWFHeader *r = new SWFHeader;
	//	fread(&header,sizeof(header),1,f);
	r->signature = getc(f);
	if (r->signature == 'C') {
		cerr << "file compressed,not finished\n";
		exit(1);
	}
	r->signature2 = getc(f);
	r->signature3 = getc(f);
	r->version = getc(f);
	fread(&r->file_length, 4, 1, f);
	r->frame_size = Rect::from_file(f);
	fread(&r->frame_rate, 2, 1, f);
	fread(&r->frame_count, 2, 1, f);
	return r;
}
void SWFHeader::print() {
	clog << "swf_header::";
	clog << signature << signature2 << signature3 << ",version:"
			<< (uint) version << ",file_length" << (uint) file_length << endl;
	clog << "frame_size:";
//	clog<<endl;
	frame_size->print();
//	clog<<endl;
	clog << "frame_rate:" << (int) frame_rate << ",frame_count:"
			<< (int) frame_count << "\n";
}

